﻿/**业务对象格式化**/

/**行政区域格式化**/
function loadAdmDiv() {
    _admdiv = $.ajax({ url: "/api/data/regioncode", async: false, dataType: 'json' }).responseJSON[0];
}

var _admdiv;//行政区域json
function formatAdmdiv(val, row) {
    if (!val || !_admdiv) return "";

    var code1 = RecursiveAdmDiv(_admdiv, val);
    if (code1 == null) return "";
    if (code1.id == val) return code1.text;


    var code2 = RecursiveAdmDiv(code1, val);
    if (code2 == null) return "";
    if (code2.id == val) return code1.text + code2.text;

    var code3 = RecursiveAdmDiv(code2, val);
    if (code3 == null) return "";
    if (code3.id == val) return code1.text + code2.text + code3.text;

    return val;
}

function RecursiveAdmDiv(code, val) {
    var result = null;
    if (code.children) {
        for (var i = 1; i < code.children.length; i++) {
            if (val < code.children[i].id) {
                result = code.children[i - 1];
                break;
            }
        }
    }

    return result;
}


/**观测站文本格式化**/
function formatStation(val, row) {
    var result = "";
    if (_stations && val)
    {
        _stations.forEach(function (station) {
            if (station.id == val) {
                result = station.text;
                return false;
            }
            return true;
        });
    }
   

    return result;
}

/**行政等级格式化**/
function formatAdmgrd(val, row) {
    var result = "";
    switch(val)
    {
        case 15:
            result = "国道";
            break;
        case 16:
            result = "省道";
            break;
        case 17:
            result = "县道";
            break;
        case 18:
            result = "乡道";
            break;
        case 19:
            result = "村道";
            break;
        case 20:
            result = "专用道路";
            break;
        default:
            result += val;
    }
    return result;
}


/**行政等级格式化**/
function formatAdmgrdS(val, row) {
    if (val != undefined && val.length >= 1) {
        var result = "";
        var strs = new Array();
        strs = val.split(",");
        for (i = 0; i < strs.length ; i++) {
            val = parseInt(strs[i]);
            switch (val) {
                case 15:
                    result += "国道,";
                    break;
                case 16:
                    result += "省道,";
                    break;
                case 17:
                    result += "县道,";
                    break;
                case 18:
                    result += "乡道,";
                    break;
                case 19:
                    result += "村道,";
                    break;
                case 20:
                    result += "专用道路,";
                    break;
                default:
                    result += val;
            }
        }
        return result;
    }else { return ""; }
}

/**路面类型格式化**/
function formatPvmttype(val, row) {
    var result = "";
    switch (val) {
        case 21:
            result = "沥青路面";
            break;
        case 22:
            result = "水泥路面";
            break;
        case 23:
            result = "砂石路面";
            break;
        default:
            result += val;
    }
    return result;
}


/**路面类型格式化**/
function formatPvmttypeS(val, row) {
    if (val != undefined && val.length >= 1) {
        var result = "";
        var strs = new Array();
        strs = val.split(",");
        for (i = 0; i < strs.length ; i++) {
            val = parseInt(strs[i]);
            switch (val) {
                case 21:
                    result += "沥青路面,";
                    break;
                case 22:
                    result += "水泥路面,";
                    break;
                case 23:
                    result += "砂石路面,";
                    break;
                default:
                    result += val;
            }
        }
        return result;
    }
    else { return "";}
}

/**层位格式化**/
function formatLayer(val, row) {
    var result = "";
    switch (val) {
        case 30:
            result = "上面层";
            break;
        case 45:
            result = "中面层";
            break;
        case 50:
            result = "下面层";
            break;
        case 55:
            result = "基层";
            break;
        case 75:
            result = "底基层";
            break;
        case 95:
            result = "垫层";
            break;
        case 100:
            result = "土基";
            break;
        default:
            result += val;
    }
    return result;
}

/**结构层材料格式化**/
function formatStrmat(val, row) {
    var result = "";
    switch (val) {
        case 31:
            result = "AC-13";
            break;
        case 32:
        case 46:
            result = "AC-16";
            break;
        case 33:
            result = "sup-13";
            break;
        case 34:
            result = "sup-16";
            break;
        case 35:
            result = "SMA-13";
            break;
        case 36:
            result = "SMA-16";
            break;
        case 37:
            result = "OGFC-13";
        case 38:
            result = "OGFC-16";
            break;
        case 39:
            result = "沥青碎石";
            break;
        case 40:
            result = "沥青贯入式";
            break;
        case 41:
            result = "水泥混凝土板";
        case 47:
        case 52:
            result = "AC-20";
            break;
        case 48:
            result = "sup-19";
            break;
        case 49:
        case 53:
            result = "sup-25";
        case 51:
            result = "AC-25";
            break;
        case 56:
        case 76:
            result = "水泥稳定碎石";
            break;
        case 57:
        case 77:
            result = "水泥稳定砂砾";
            break;
        case 58:
        case 78:
            result = "水泥稳定土";
            break;
        case 59:
        case 79:
            result = "石灰稳定碎石";
        case 60:
        case 80:
            result = "石灰稳定砂砾";
            break;
        case 61:
        case 81:
            result = "石灰土";
            break;
        case 62:
        case 82:
            result = "二灰碎石";
            break;
        case 63:
        case 83:
            result = "二灰砂砾";
        case 64:
        case 84:
            result = "二灰土";
            break;
        case 65:
        case 85:
            result = "石灰工业废渣稳定碎石";
            break;
        case 66:
        case 86:
            result = "石灰工业废渣稳定砂砾";
            break;
        case 67:
        case 87:
            result = "石灰工业废渣稳定土";
        case 68:
        case 88:
            result = "ATB-25";
            break;
        case 69:
        case 89:
            result = "ATB-30";
            break;
        case 70:
        case 90:
            result = "LSM-30";
            break;
        case 71:
        case 91:
            result = "LSM-35";
            break;
        case 72:
        case 92:
        case 97:
            result = "级配碎石";
            break;
        case 96:
            result = "级配砾石";
            break;
        case 98:
            result = "砂砾垫层";
            break;
        default:
            result += val;
    }
    return result;
}


/**技术等级格式化**/
function formatTechnicalype(val, row) {
    var result = "";
    switch (val) {
        case 141:
            result = "特大桥";
            break;
        case 142:
            result = "大桥";
            break;
        case 143:
            result = "中桥";
            break;
        case 144:
            result = "小桥";
            break;
        case 146:
            result = "特长隧道";
            break;
        case 147:
            result = "长隧道";
            break;
        case 148:
            result = "中隧道";
            break;
        case 149:
            result = "短隧道";
            break;
        default:
            result += val;
    }
    return result;
}

/**结构类型格式化**/
function formatSturcturetype(val, row) {
    var result = "";
    switch (val) {
        case 111:
            result = "桥梁";
            break;
        case 112:
            result = "公路桥";
            break;
        case 113:
            result = "铁路桥";
            break;
        case 114:
            result = "公铁两用桥";
            break;
        case 115:
            result = "闸坝桥";
            break;
        case 116:
            result = "人行桥";
            break;
        case 117:
            result = "通道桥";
            break;
        case 118:
            result = "其他";
                break;
        case 120:
            result = "隧道";
            break;
        case 121:
            result = "公路隧道";
            break;
        case 122:
            result = "山岭隧道";
            break;
        case 123:
            result = "水下隧道";
            break;
        case 125:
            result = "涵洞";
            break;
        case 126:
            result = "圆管涵";
            break;
        case 127:
            result = "箱涵";
            break;
        case 128:
            result = "盖板涵";
            break;
        case 129:
            result = "拱涵";
            break;
        default:
            result += val;
    }
    return result;
}



/**道路技术等级格式化**/
function formatRoadClass(val, row) {
    var result = "";
    
    switch (val) {
        case 160:
            result = "高速公路";
            break;
        case 161:
            result = "一级公路";
            break;
        case 162:
            result = "二级公路";
            break;
        case 163:
            result = "三级公路";
            break;
        case 164:
            result = "四级公路";
            break;
        default:
            result += val;
    }
    return result;
}

function formatRoadClassS(val, row) {
   
    if (val != undefined && val.length >= 1) {
        var result = "";
        var strs = new Array();
        strs = val.split(",");
        for (i = 0; i < strs.length ; i++) {
            val = parseInt(strs[i]);
            switch (val) {
                case 160:
                    result += "高速公路,";
                    break;
                case 161:
                    result += "一级公路,";
                    break;
                case 162:
                    result += "二级公路,";
                    break;
                case 163:
                    result += "三级公路,";
                    break;
                case 164:
                    result += "四级公路,";
                    break;
                default:
                    result += val;
            }
        }

        return result;
    }
    else { return "";}
    
}

/**行车方向格式化**/
function formatDirection(val, row) {
    var result = "";
    switch (val) {
        case 11:
            result = "上行";
            break;
        case 12:
            result = "下行";
            break;
        case 13:
            result = "全幅";
            break;
        default:
            result += val;
    }
    return result;

}


function formatEvalucalss(val, row) {
    //console.log(val);
    var result = "";
    if (val == null) {
        return "";
    }
    else {
        switch (val) {
            case 255:
                result = "优";
                break;
            case 256:
                result = "良";
                break;
            case 257:
                result = "中";
                break;
            case 258:
                result = "次";
                break;
            case 259:
                result = "差";
                break;
            default:
                result += val;
        }
        return result;
    }
    //console.log(result);
    

}


/**路面类型格式化**/
function formatRoadSurface(val, row) {
    var result = "";
    switch (val) {
        case 165:
            result = "半刚性基层沥青路面";
            break;
        case 166:
            result = "复合式路面";
            break;
        case 167:
            result = "柔性基层沥青路面";
            break;
        case 168:
            result = "普通混凝土路面";
            break;
        case 169:
            result = "钢筋混凝土路面";
            break;
        case 170:
            result = "连续配筋水泥混凝土路面";
            break;
        case 171:
            result = "钢纤维混凝土路面";
            break;
        case 172:
            result = "砂石路面";
            break;
        default:
            result += val;
    }
    return result;

}



/**土基类型格式化**/
function formatSubgrade(val, row) {
    var result = "";
    switch (val) {
        case 180:
            result = "岩溶地区路基";
            break;
        case 181:
            result = "红粘土地区路基";
            break;
        case 182:
            result = "高液限土地区路基";
            break;
        case 183:
            result = "膨胀土地区路基";
            break;
        case 184:
            result = "黄土地区路基";
            break;
        case 185:
            result = "盐泽土路基";
            break;
        case 186:
            result = "冻土地区路基";
            break;
        case 187:
            result = "风沙地区路基";
            break;
        case 188:
            result = "软基";
            break;
        case 189:
            result = "常规土";
            break;
        default:
            result += val;
    }
    return result;

}

/**路肩类型格式化**/
function formatShoulder(val, row) {
    var result = "";
    switch (val) {
        case 191:
            result = "土路肩";
            break;
        case 192:
            result = "硬路肩";
            break;
        default:
            result += val;
    }
    return result;

}

/**路缘石类型格式化**/
function formatCurb(val, row) {
    var result = "";
    switch (val) {
        case 195:
            result = "水泥混凝土";
            break;
        case 196:
            result = "天然石材";
            break;
        default:
            result += val;
    }
    return result;

}


/**汽车类型格式化**/
function formatCar(val, row) {
    var result = "";
    switch (val) {
        case 1000:
            result = "载重汽车-小型";
            break;
        case 1001:
            result = "载重汽车-中型";
            break;
        case 1002:
            result = "载重汽车-大型";
            break;
        case 1003:
            result = "载重汽车-特大型";
            break;
        case 1004:
            result = "客车-小型";
            break;
        case 1005:
            result = "客车-大型";
            break;
        case 1006:
            result = "拖挂车";
            break;
        case 1007:
            result = "集装箱车";
            break;
        case 1008:
            result = "拖拉机";
            break;
        default:
            result += val;
    }
    return result;

}



/**轴型格式化**/
function formatShaft(val, row) {
    var result = "";
    switch (val) {
        case 1100:
            result = "1s+1s";
            break;
        case 1101:
            result = "1s+1d";
            break;
        case 1102:
            result = "1s+2d";
            break;
        case 1103:
            result = "1s+1s+2d";
            break;
        case 1104:
            result = "1s+1d+1d";
            break;
        case 1105:
            result = "1s+1d+2d";
            break;
        case 1106:
            result = "1s+1d+3d";
            break;
        case 1107:
            result = "1s+2d+3d";
            break;
        case 1108:
            result = "1s+2d+2d";
            break;
        default:
            result += val;
    }
    return result;

}


/**事故类别格式化**/
function formatAccidentTyp(val, row) {
    var result = "";
    switch (val) {
        case 1200:
            result = "特大";
            break;
        case 1201:
            result = "重大";
            break;
        case 1202:
            result = "较大";
            break;
        case 1203:
            result = "一般";
            break;
        default:
            result += val;
    }
    return result;

}


/**事故原因格式化**/
function formatAccidentTyp(val, row) {
    var result = "";
    switch (val) {
        case 1300:
            result = "视距不足";
            break;
        case 1301:
            result = "标志牌设置缺陷";
            break;
        case 1302:
            result = "长大纵坡路段";
            break;
        case 1303:
            result = "平曲线半径小";
            break;
        case 1304:
            result = "其他原因";
            break;
        default:
            result += val;
    }
    return result;

}


/**分析类型**/
function formatAnasType(val, row) {
    var result = "";
    switch (val) {
        case 20010:
            result = "单年度分配";
            break;
        case 20011:
            result = "多年度分配";
            break;
        default:
            result += val;
    }
    return result;

}



/**分析类型**/
function formatAnnuType(val, row) {
    var result = "";
    switch (val) {
        case 20020:
            result = "资金不受限";
            break;
        case 20021:
            result = "资金受限";
            break;
        default:
            result += val;
    }
    return result;

}


function formatMainType(val, row) {
    var result = "";
    switch (val)
    {
        case 12000:
            result = "日常养护";
            break;
        case 12001:
            result = "预防性养护";
            break;
        case 12002:
            result = "中修";
            break;
        case 12003:
            result = "大修";
            break;
        default:
            result += val;
    }
    return result;
}


function formatYesNoType(val, row)
{
    var result = "";
    switch (val) {
        case 1:
            result = "<img src='/Scripts/Jquery/easyui/themes/icons/ok.png'></img>";
            break;
        case 0:
            result = "<img src='/Scripts/Jquery/easyui/themes/icons/no.png'></img>";
            break;
        default:
            result += "";
    }
    return result;
}

/**养护类型对应的阴影颜色**/
function formatColor(val, row) {
    var result = "";
    switch (val) {
        case 12000:
            result = "#FFF5EE";
            break;
        case 12001:
            result = "#FFDAB9";
            break;
        case 12002:
            result = "#FFA500";
            break;
        case 12003:
            result = "#FF6A6A";
            break;
        default:
            result += val;
    }
    return result;
}